package com.carleasoft.mps.cms.business.resource.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.message.bean.po.MessageNotePageQueryPo;
import com.carleasoft.mps.cms.business.message.bean.vo.MessageNoteVo;
import com.carleasoft.mps.cms.business.message.service.MessageNoteService;
import com.carleasoft.mps.cms.business.resource.bean.entity.LibraryEntity;
import com.carleasoft.mps.cms.business.resource.bean.entity.ReasourceCollectEntity;
import com.carleasoft.mps.cms.business.resource.bean.entity.ReasourceEntity;
import com.carleasoft.mps.cms.business.resource.bean.po.ReasourcePageQueryPo;
import com.carleasoft.mps.cms.business.resource.bean.vo.ReasourcePageQueryVo;
import com.carleasoft.mps.cms.business.resource.service.ReasourceService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.carleasoft.mps.cms.business.resource.bean.po.DoorPagePo;
import com.carleasoft.mps.cms.business.resource.bean.vo.DoorLibraryVo;
import com.carleasoft.mps.cms.business.resource.bean.vo.DoorListVo;
import com.carleasoft.mps.cms.business.resource.service.ReasourceService;
import com.carleasoft.mps.core.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author: yangHao
 * @createDate:2023/5/23
 * @description:
 */
@RestController
@RequestMapping("/door")
public class DoorController {
    @Autowired
    private MessageNoteService messageNoteService;
    @Autowired
    private ReasourceService reasourceService;

    /**
     * 门户-信件公开-分页查询
     */
    @PostMapping("/massageNotePageQuery")
    public R<Page<MessageNoteVo>> pageQuery(@RequestBody MessageNotePageQueryPo messageNotePageQueryPo) {
        return R.ok(messageNoteService.pageQuery1(messageNotePageQueryPo));
    }

    /**
     * 门户-教学资源八库各种类型
     *
     * @param doorPagePo
     * @return
     */
    @PostMapping("/doorList")
    public R doorList(@RequestBody DoorPagePo doorPagePo) {
        List<DoorListVo> doorListVos = reasourceService.doorList(doorPagePo);
        return R.ok(doorListVos);
    }

    /**
     * 门户-教学资源八库
     *
     * @return
     */
    @PostMapping("/doorLibrary")
    public R doorLibrary() {
        List<DoorLibraryVo> doorLibraryVos = reasourceService.doorLibrary();
        return R.ok(doorLibraryVos);
    }


    /**
     * 门户教学资源八库-分页
     *
     * @param reasourcePageQueryPo
     * @param request
     * @return
     */
    @PostMapping("/doorPageQuery")
    public R doorPageQuery(@RequestBody ReasourcePageQueryPo reasourcePageQueryPo, HttpServletRequest request) {
        Page<ReasourcePageQueryVo> reasourcePageQueryVoPage = reasourceService.doorPageQuery(new Page(reasourcePageQueryPo.getCurrent(), reasourcePageQueryPo.getSize()), reasourcePageQueryPo, request);
        return R.ok(reasourcePageQueryVoPage);
    }

    /**
     * 查询所属库列表
     *
     * @return
     */
    @PostMapping("/getLibrary")
    public R getLibrary() {
        List<LibraryEntity> libraryEntities = reasourceService.getLibrary();
        return R.ok(libraryEntities);
    }

    /**
     * 根据所属库编码查询分类
     *
     * @param reasourceEntity
     * @return
     */
    @PostMapping("/getCategory")
    public R getCategory(@RequestBody LibraryEntity reasourceEntity) {
        IBeanUtil.paramVerify(reasourceEntity, "libraryCode");
        List<ReasourceCollectEntity> reasourceCollectEntities = reasourceService.getCategory(reasourceEntity);
        return R.ok(reasourceCollectEntities);
    }

}
